package Clain;

import Factory.AgriculturalMachine;
import Command.RemoteController;
import State.PausedState;

public class ObstacleHandler extends AbstractSafetyHandler {
    private RemoteController remoteController;

    public ObstacleHandler(RemoteController remoteController) {
        this.remoteController = remoteController;
    }

    @Override
    protected boolean canHandle(SafetyEvent event) {
        return event.getType() == SafetyEventType.OBSTACLE_DETECTED;
    }

    @Override
    protected void process(SafetyEvent event) {
        System.out.println("【障碍物检测处理器】处理事件: " + event.getDescription());

        // 获取受影响的农机
        AgriculturalMachine affectedMachine = (AgriculturalMachine) event.getSource();


        // 2. 记录障碍物信息
        System.out.println("- 障碍物位置: " + event.getLocation());
        System.out.println("- 障碍物类型: " + event.getDetails());

        // 3. 启动避障策略
        System.out.println("- 启动避障路径规划");
        // 这里调用路径规划模块
        // Path newPath = pathPlanningManager.generateAvoidancePath(affectedMachine, event.getLocation());

        // 4. 恢复作业
        // remoteController.executeCommand(affectedMachine, new ResumeCommand(newPath));

        event.setResolved(true);
    }
}
